<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:s="http://jboss.org/seam/faces"
	xmlns:p="http://primefaces.org/ui" template="/_template.xhtml">

	<ui:define name="corpo">
		<h:form>

				<h2>
					<h:outputText value="Gerar Script" />

				</h2>

				<p:messages></p:messages>
				<fieldset id = "fild">
					<legend>Gerador de Script</legend>
					        
        
					
					<h:outputLabel value = "Cliente: " />
						<p:autoComplete value="#{geraScriptBean.cliente}" id="cliente" completeMethod="#{geraScriptBean.completaCliente}"
							var ="c" itemLabel="#{c.sigla}" converter="conversorcliente" itemValue="#{c}" forceSelection="true" disabled="#{not empty geraScriptBean.cliente.id}"
							required="true" requiredMessage="Favor Preencher o cliente">

					</p:autoComplete>
				<h:outputLabel value="Tp. Amb. Cliente: " ></h:outputLabel>
					<h:selectOneMenu value="#{geraScriptBean.idtpAmbienteCliente}"   id="tpAmbienteCliente" required="true" requiredMessage="Favor o tipo de ambiente do cliente">
			    		<f:selectItem itemLabel="Escolha" />
			    		<f:selectItems value="#{geraScriptBean.ambienteClientes}" var="tpAmbiente" itemValue="#{tpAmbiente.id}" itemLabel="#{tpAmbiente.tipo}" />
			 
			    	</h:selectOneMenu>
 
 
 			<h:outputLabel value = "Base restaurada: " />
			 <h:selectOneMenu  value="#{geraScriptBean.restaurada}" disabled="#{not empty geraScriptBean.cliente.id}" >  
			 	<f:selectItem itemLabel="NAO" itemValue="nao" />
                <f:selectItem itemLabel="SIM" itemValue="sim" />  
                   
             </h:selectOneMenu> 
             					  <h:outputLabel  value ="Numero Chamado: "  disabled="#{not empty geraScriptBean.cliente.id}" />
            		 <h:inputText id="chamado" value="#{geraScriptBean.historico.nrChamado}" required="true" requiredMessage="Preencher o numero do chamado"  disabled="#{not empty geraScriptBean.cliente.id}"  />
					
					
 					<h:commandButton action="#{geraScriptBean.selecionar}" value="selecionar" rendered="#{empty geraScriptBean.cliente.id}"></h:commandButton>
					
					
					<h:outputLabel value = "Ambiente: " rendered="#{not empty geraScriptBean.cliente.id}" />
					<h:selectOneMenu value="#{geraScriptBean.idAmbiente}"  rendered="#{not empty geraScriptBean.cliente.id}">
						<f:selectItems value="#{geraScriptBean.ambientes}" var="ambiente"
									   itemValue="#{ambiente.id}" itemLabel="#{ambiente}"></f:selectItems>
					</h:selectOneMenu>
					
					  <h:outputLabel  value ="Nr Revisao Restauracao: " rendered="#{geraScriptBean.baseRestaurada}" />
            		 <h:inputText id="revisao" value="#{geraScriptBean.idRevisaoRestaurada}" required="true" requiredMessage="Preencher o numero da revisão atual" rendered="#{geraScriptBean.baseRestaurada}" />
					
			    	<h:commandButton   action="#{geraScriptBean.gerar}" value="Gerar Script" rendered="#{geraScriptBean.botao}" />
       				<h:commandButton action="#{geraScriptBean.limpa}" value="Limpar" rendered="#{not empty geraScriptBean.cliente.id}" immediate="true" />
			      	
				</fieldset>
		</h:form> 
		
		<h:form id="form">  
		<fieldset>
			<legend>Log Geracao</legend>
    		<h:outputText id="txt_count" value="#{geraScriptBean.log}" escape="false" />  
      	<p:poll interval="3" update="txt_count" />  
      	</fieldset>
		</h:form> 
		
	  <h:form rendered="#{not empty geraScriptBean.historico.id}">
			<h2>Historico da Geracao</h2>
			<h:dataTable value="#{geraScriptBean.historicos}" var="historico"
				styleClass="dados" rowClasses="impar,par">

		<h:column>
					<f:facet name="header">ID</f:facet>
			#{historico.id}
		</h:column>
		<h:column>
		<f:facet name="header">Cliente</f:facet>
			#{historico.ambiente.cliente.sigla}
		</h:column>

		<h:column>
					<f:facet name="header">Intervalo Revisao: </f:facet>
			#{historico.revisaoInicial} -  #{historico.revisaoFinal}
		</h:column>  
  	<h:column>   
   					<f:facet name="header">Download</f:facet>   
  		<p:commandButton id="dados" value="Dados" ajax="false" onclick="PrimeFaces.monitorDownload(start, stop)"  icon="ui-icon-arrowthichk-s">  
    		<p:fileDownload value="#{geraScriptBean.fileDados}" />  
		</p:commandButton>  
		<p:commandButton id="estrutura" value="Estrutura" ajax="false" onclick="PrimeFaces.monitorDownload(start, stop)"  icon="ui-icon-arrowthichk-s">  
    		<p:fileDownload value="#{geraScriptBean.fileEstrutura}" />  
		</p:commandButton>   
  	</h:column>
  	
  		<h:column>
  			<f:facet name="header">Autor</f:facet>
  			#{geraScriptBean.historico.usuario.nome}
  	</h:column>   
			</h:dataTable>
		</h:form>


	</ui:define>
</ui:composition>